#include "OperatorNode.h"
#include <sstream>

using namespace operatorNode;

OperatorNode::OperatorNode(OperatorType t)
:type_(t){
	Kind(node::Node::k_operator);
}

std::string OperatorNode::Execute()
{
	std::string left = "0";
	std::string right = "0";
	if (Left() != NULL)
		left = Left()->Execute();

	if (Right() != NULL)
		right = Right()->Execute();

	float l = atof(left.c_str());
	float r = atof(right.c_str());

	float o = 0;
	switch (Type()){
		case ot_add: o = l+r;
			break;
		case ot_mul: o = l*r;
			break;
		case ot_sub: o = l - r;
			break;
		case ot_div: o = l/r;
			break;
	}

	char c[10];
	int d,si;
	std::stringstream ss;
	ss << o;
	return ss.str();
	//std::string s = std::string(_ecvt(o, 10, &d, &si));
	//std::string s = std::string(itoa(o, c, 10));

//	return s;
}